$(function(){
    /**
     * 保存按钮事件
     */
    $('#btn_save').on("click", function () {
        //var ret = $("#hdRegisterForm").form('validate');
        //表单验证
        if($("#addForm").form('validate')){
            layer.confirm("确定保存？",{btn:['确定','取消']},function(){
                var layerIndex=parent.layer.getFrameIndex(window.name); //获取窗口索引
                //序列化表单数据
                var data = $("#addForm").serializeArray();
                console.log(data);
                $.ajax({
                    url:ROOT_PATH + '/risk/matrix/addRiskPossibilityInfo.shtml',//提交地址
                    data:data,//将表单数据序列化
                    type:"POST",
                    dataType:"json",
                    success:function(result){
                        if (result.success){
                            layer.msg(result.message,{time:1000,icon:1},function(){
                                WindowManager.closeLayer({
                                    returnValue:""
                                });
                                //parent.layer.close(layerIndex);
                            });
                        }else{
                            layer.msg(result.message,{time:1000,icon:1},function(){
                                //parent.layer.close(layerIndex);
                            });
                        }
                    }
                });
            });
        }else{
            layer.msg("请按规则填写信息!",{time:1000,icon:2});
        }

    });
});
/**
 * 定义表单验证
 */
$.extend($.fn.validatebox.defaults.rules, {
    integer: {// 验证非负整数
        validator: function (value) {
            //return /^[+]?[1-9]+\d*$/i.test(value);
            return  /^\d+$/.test(value);
        },
        message: '请输入整数'
    }

});